
#ifndef __SECURITY_TOKEN_KEY_H
#define __SECURITY_TOKEN_KEY_H

#include "../db/KeyDB.h"
#include "../crypt/SigningKey.h"
#include "../crypt/CheckingKey.h"
#include "SecurityToken.h"

/** Function type for callback with key authentication. */
typedef int (*stoken_key_functor)(LIBSSH2_SESSION *, unsigned char **,
   size_t *, const unsigned char *, size_t, void **);

/** A security token based on a key pair (possibly from a key
 * database). */
class SecurityTokenKey : public SecurityToken
{
   public:
      SecurityTokenKey(const char *isgnname, const char *ichkname, const char *ipassword, KeyDB *ikdb);
      SecurityTokenKey(const SigningKey &isgnkey, const CheckingKey &ichkkey);
      virtual ~SecurityTokenKey();
      static int keyCallback(LIBSSH2_SESSION *session,
         unsigned char **sig, size_t *sig_len, const unsigned char *data,
         size_t data_len, void **abstract);
      virtual stoken_key_functor getKeyCallback() const
      {
         return (stoken_key_functor)(&keyCallback);
      }
      int authenticateSSHSession(LIBSSH2_SESSION *tsession, const char *username);
      virtual sshauthtype getAuthenticationType() { return SSH_AUTH_TYPE_KEY; }
      virtual int wasTried() { return tried; }
   protected:
      /** Signing key for the challenge response. */
      SigningKey *sgnkey;
      /** Checking key for the challenge response. */
      CheckingKey *chkkey;
      /** Pointer pointer self. */
      SecurityToken *myself;
};

#endif
